Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • xtivreg2* (factor-variable operators not allowed)

    Hi, im new in using STATA

    im trying to use xtivreg2 and control for time at the same time by using i.year im facing problem as it give me (factor-variable operators not allowed)

    How can i solve this problem

    HTML Code:
    . ssc install xtivreg2, replace
    checking xtivreg2 consistency and verifying not already installed...
    all files already exist and are up to date.
    
    . xtivreg2 EQUITY CSO  FSIZE OP_CF SD_OCF TAX   BM LEV MA DPP RPP PSIZE   DR  Gov_score Sustain_Perf Sust_Commit   i.year (CSO = Instrumental),  fe  robust
    factor-variable operators not allowed
    r(101);

  • #2
    tab year , generate(yr)
    then add yr* as regressors

    Comment


    • #3
      look at ivreghdfe too.

      ssc install ivreghdfe

      Comment


      • #4
        Thanks George

        plesae i did what you suggested

        but it give me

        Warning - singleton groups detected. 7 observation(s) not used.
        Warning - duplicate variables detected
        Duplicates: CSO
        Warning - collinearities detected
        Vars dropped: yr19


        please what you sugeest i used ivreghdfe but the result was bad totally different than my the main regression



        HTML Code:
        xtivreg2 EQUITY CSO  FSIZE OP_CF SD_OCF TAX   BM LEV MA DPP RPP PSIZE   DR  Gov_score Sustain_Perf Sust_Commit   yr*  (CSO = Instrumental),  fe  robust
        Warning - singleton groups detected.  7 observation(s) not used.
        Warning - duplicate variables detected
        Duplicates:         CSO
        Warning - collinearities detected
        Vars dropped:       yr19
        
        FIXED EFFECTS ESTIMATION
        ------------------------
        Number of groups =       281                    Obs per group: min =         2
                                                                       avg =      14.4
                                                                       max =        19
        Warning - duplicate variables detected
        Duplicates:    CSO
        Warning - collinearities detected
        Vars dropped:  yr19
        
        OLS estimation
        --------------
        
        Estimates efficient for homoskedasticity only
        Statistics robust to heteroskedasticity
        
                                                              Number of obs =     4044
                                                              F( 33,  3730) =    86.67
                                                              Prob > F      =   0.0000
        Total (centered) SS     =  84.86900113                Centered R2   =   0.4795
        Total (uncentered) SS   =  84.86900113                Uncentered R2 =   0.4795
        Residual SS             =  44.17832177                Root MSE      =    .1084
        
        ------------------------------------------------------------------------------
                     |               Robust
              EQUITY | Coefficient  std. err.      z    P>|z|     [95% conf. interval]
        -------------+----------------------------------------------------------------
                 CSO |  -.0245001   .0061191    -4.00   0.000    -.0364933    -.012507
               FSIZE |   .0088576   .0077466     1.14   0.253    -.0063254    .0240406
               OP_CF |  -.0483011    .061843    -0.78   0.435     -.169511    .0729089
              SD_OCF |  -.3418531   .1272211    -2.69   0.007    -.5912019   -.0925043
                 TAX |  -.0103754   .0072893    -1.42   0.155    -.0246622    .0039114
                  BM |  -.0197849   .0115391    -1.71   0.086    -.0424011    .0028313
                 LEV |  -.0372171   .0293147    -1.27   0.204    -.0946729    .0202386
                  MA |   .0062033   .0148769     0.42   0.677    -.0229549    .0353615
                 DPP |   .1404479   .0252074     5.57   0.000     .0910422    .1898535
                 RPP |   .1150126   .0316234     3.64   0.000     .0530318    .1769934
               PSIZE |   .0144853   .0083952     1.73   0.084    -.0019689    .0309396
                  DR |   .0432099   .0069073     6.26   0.000     .0296719    .0567478
           Gov_score |  -.0000846   .0001207    -0.70   0.483    -.0003211    .0001519
        Sustain_Perf |   -.000248   .0001865    -1.33   0.183    -.0006135    .0001174
         Sust_Commit |  -.0082043   .0063486    -1.29   0.196    -.0206473    .0042387
                 yr1 |   .2679397   .0284086     9.43   0.000       .21226    .3236194
                 yr2 |   .2690732   .0263761    10.20   0.000     .2173771    .3207693
                 yr3 |   .2544232    .026361     9.65   0.000     .2027566    .3060898
                 yr4 |   .2213576   .0258864     8.55   0.000     .1706212     .272094
                 yr5 |   .1762084   .0238107     7.40   0.000     .1295402    .2228766
                 yr6 |   .1643163   .0250262     6.57   0.000      .115266    .2133667
                 yr7 |   .1842541   .0243775     7.56   0.000     .1364751     .232033
                 yr8 |   .1758366   .0228243     7.70   0.000     .1311019    .2205713
                 yr9 |   .1845816   .0242418     7.61   0.000     .1370686    .2320946
                yr10 |   .1536788    .023142     6.64   0.000     .1083213    .1990362
                yr11 |   .1567697   .0239015     6.56   0.000     .1099237    .2036158
                yr12 |   .1440244   .0221715     6.50   0.000      .100569    .1874798
                yr13 |   .1423335   .0236824     6.01   0.000     .0959168    .1887502
                yr14 |   .1302711   .0248925     5.23   0.000     .0814826    .1790595
                yr15 |   .0714838   .0220454     3.24   0.001     .0282756    .1146921
                yr16 |   .0887847   .0265665     3.34   0.001     .0367152    .1408542
                yr17 |   .1153496    .028267     4.08   0.000     .0599473    .1707518
                yr18 |   .0723285   .0271801     2.66   0.008     .0190564    .1256006
                yr19 |          0  (omitted)
        ------------------------------------------------------------------------------
        Hansen J statistic (overidentification test of all instruments):         7.084
                                                           Chi-sq(1) P-val =    0.0078
        ------------------------------------------------------------------------------
        Included instruments: CSO FSIZE OP_CF SD_OCF TAX BM LEV MA DPP RPP PSIZE DR
                              Gov_score Sustain_Perf Sust_Commit yr1 yr2 yr3 yr4 yr5 yr6
                              yr7 yr8 yr9 yr10 yr11 yr12 yr13 yr14 yr15 yr16 yr17 yr18
        Excluded instruments: Instrumental
        Duplicates:           CSO
        Dropped collinear:    yr19
        ------------------------------------------------------------------------------
        
        . 
        end of do-file

        Comment


        • #5

          *Warning - singleton groups detected. 7 observation(s) not used. You've perfectly predicted 7 observations with your X's. It happens. Figure out why; but it may not be a problem. It's probably some groups having only 2 years of data. *Warning - duplicate variables detected *Duplicates: CSO Drop CSO as a regressor. It is being treated as endogenous. *Warning - collinearities detected *Vars dropped: yr19 Not a problem. Just avoiding the dummy trap. You could say yr2-yr19 in place of yr*.
          Code:
            
           ivreghdfe EQUITY FSIZE OP_CF SD_OCF TAX  BM LEV MA DPP RPP PSIZE DR Gov_score Sustain_Perf Sust_Commit (CSO = Instrumental),  absorb(id year) cluster(id)

          Comment


          • #6
            Thank you very much George for Gudance and support

            plesae i have two enquires if you can advice me on how to solve them

            1. i want to identify this singleton groups detected. 7 observation(s) so i can delete them in order to have same same number of observations in main regression and 2SLS
            2. the Endogeneity test does not appear for me , I'm not sure why , is this is because of singleton groups and is there a way to display the Endogeneity test results

            HTML Code:
            .  ivreghdfe EQUITY FSIZE OP_CF SD_OCF TAX  BM LEV MA DPP RPP PSIZE DR Gov_score Sustain_Perf Sust_Commit (CSO = Instrumental), first absorb(id year) robust
            (dropped 7 singleton observations)
            (MWFE estimator converged in 7 iterations)
            
            First-stage regressions
            -----------------------
            
            
            First-stage regression of CSO:
            
            Statistics robust to heteroskedasticity
            Number of obs =                   4044
            ------------------------------------------------------------------------------
                         |               Robust
                     CSO | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
            -------------+----------------------------------------------------------------
            Instrumental |   .0156519   .0025056     6.25   0.000     .0107394    .0205644
                   FSIZE |    .008078   .0195748     0.41   0.680    -.0303003    .0464563
                   OP_CF |  -.0828493   .1580706    -0.52   0.600    -.3927627     .227064
                  SD_OCF |   1.446089   .3084335     4.69   0.000     .8413738    2.050804
                     TAX |   .0273629   .0207085     1.32   0.186    -.0132381    .0679639
                      BM |  -.0247828   .0320633    -0.77   0.440    -.0876462    .0380806
                     LEV |   .1534906   .0765237     2.01   0.045     .0034582     .303523
                      MA |  -.0171832    .039259    -0.44   0.662    -.0941545     .059788
                     DPP |  -.0248049   .0594157    -0.42   0.676    -.1412954    .0916856
                     RPP |  -.1013338   .0869353    -1.17   0.244    -.2717791    .0691115
                   PSIZE |   .0500369   .0181621     2.76   0.006     .0144282    .0856456
                      DR |  -.0142629   .0173658    -0.82   0.412    -.0483102    .0197845
               Gov_score |   .0003102    .000337     0.92   0.357    -.0003506    .0009709
            Sustain_Perf |   .0011279   .0005123     2.20   0.028     .0001236    .0021322
             Sust_Commit |   .0079999   .0161499     0.50   0.620    -.0236636    .0396634
            ------------------------------------------------------------------------------
            F test of excluded instruments:
              F(  1,  3730) =    39.02
              Prob > F      =   0.0000
            Sanderson-Windmeijer multivariate F test of excluded instruments:
              F(  1,  3730) =    39.02
              Prob > F      =   0.0000
            
            
            
            Summary results for first-stage regressions
            -------------------------------------------
            
                                                       (Underid)            (Weak id)
            Variable     | F(  1,  3730)  P-val | SW Chi-sq(  1) P-val | SW F(  1,  3730)
            CSO          |      39.02    0.0000 |       42.31   0.0000 |       39.02
            
            NB: first-stage test statistics heteroskedasticity-robust
            
            Stock-Yogo weak ID F test critical values for single endogenous regressor:
                                               10% maximal IV size             16.38
                                               15% maximal IV size              8.96
                                               20% maximal IV size              6.66
                                               25% maximal IV size              5.53
            Source: Stock-Yogo (2005).  Reproduced by permission.
            NB: Critical values are for i.i.d. errors only.
            
            Underidentification test
            Ho: matrix of reduced form coefficients has rank=K1-1 (underidentified)
            Ha: matrix has rank=K1 (identified)
            Kleibergen-Paap rk LM statistic          Chi-sq(1)=41.78    P-val=0.0000
            
            Weak identification test
            Ho: equation is weakly identified
            Cragg-Donald Wald F statistic                                      52.18
            Kleibergen-Paap Wald rk F statistic                                39.02
            
            Stock-Yogo weak ID test critical values for K1=1 and L1=1:
                                               10% maximal IV size             16.38
                                               15% maximal IV size              8.96
                                               20% maximal IV size              6.66
                                               25% maximal IV size              5.53
            Source: Stock-Yogo (2005).  Reproduced by permission.
            NB: Critical values are for Cragg-Donald F statistic and i.i.d. errors.
            
            Weak-instrument-robust inference
            Tests of joint significance of endogenous regressors B1 in main equation
            Ho: B1=0 and orthogonality conditions are valid
            Anderson-Rubin Wald test           F(1,3730)=      9.36     P-val=0.0022
            Anderson-Rubin Wald test           Chi-sq(1)=     10.14     P-val=0.0014
            Stock-Wright LM S statistic        Chi-sq(1)=     10.30     P-val=0.0013
            
            NB: Underidentification, weak identification and weak-identification-robust
                test statistics heteroskedasticity-robust
            
            Number of observations               N  =       4044
            Number of regressors                 K  =         15
            Number of endogenous regressors      K1 =          1
            Number of instruments                L  =         15
            Number of excluded instruments       L1 =          1
            
            IV (2SLS) estimation
            --------------------
            
            Estimates efficient for homoskedasticity only
            Statistics robust to heteroskedasticity
            
                                                                  Number of obs =     4044
                                                                  F( 15,  3730) =     7.52
                                                                  Prob > F      =   0.0000
            Total (centered) SS     =  46.32975885                Centered R2   =  -0.1074
            Total (uncentered) SS   =  46.32975885                Uncentered R2 =  -0.1074
            Residual SS             =  51.30371339                Root MSE      =    .1173
            
            ------------------------------------------------------------------------------
                         |               Robust
                  EQUITY | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
            -------------+----------------------------------------------------------------
                     CSO |  -.1729897   .0609084    -2.84   0.005    -.2924066   -.0535728
                   FSIZE |   .0123795   .0083681     1.48   0.139     -.004027    .0287859
                   OP_CF |     -.0683   .0678452    -1.01   0.314    -.2013172    .0647173
                  SD_OCF |  -.1461356   .1548982    -0.94   0.346     -.449829    .1575579
                     TAX |  -.0058738   .0080836    -0.73   0.467    -.0217225    .0099749
                      BM |  -.0258302   .0125445    -2.06   0.040    -.0504249   -.0012355
                     LEV |   -.020226   .0329623    -0.61   0.540    -.0848519    .0443999
                      MA |   .0038532   .0151436     0.25   0.799    -.0258374    .0335438
                     DPP |   .1396388    .025668     5.44   0.000     .0893142    .1899635
                     RPP |   .0998273   .0365839     2.73   0.006     .0281009    .1715537
                   PSIZE |   .0209352   .0093783     2.23   0.026     .0025481    .0393223
                      DR |   .0404173   .0074463     5.43   0.000     .0258182    .0550165
               Gov_score |  -.0000358   .0001305    -0.27   0.784    -.0002918    .0002201
            Sustain_Perf |   -.000039    .000214    -0.18   0.855    -.0004586    .0003806
             Sust_Commit |  -.0079053   .0067824    -1.17   0.244     -.021203    .0053923
            ------------------------------------------------------------------------------
            Underidentification test (Kleibergen-Paap rk LM statistic):             41.775
                                                               Chi-sq(1) P-val =    0.0000
            ------------------------------------------------------------------------------
            Weak identification test (Cragg-Donald Wald F statistic):               52.182
                                     (Kleibergen-Paap rk Wald F statistic):         39.022
            Stock-Yogo weak ID test critical values: 10% maximal IV size             16.38
                                                     15% maximal IV size              8.96
                                                     20% maximal IV size              6.66
                                                     25% maximal IV size              5.53
            Source: Stock-Yogo (2005).  Reproduced by permission.
            NB: Critical values are for Cragg-Donald F statistic and i.i.d. errors.
            ------------------------------------------------------------------------------
            Hansen J statistic (overidentification test of all instruments):         0.000
                                                             (equation exactly identified)
            ------------------------------------------------------------------------------
            Instrumented:         CSO
            Included instruments: FSIZE OP_CF SD_OCF TAX BM LEV MA DPP RPP PSIZE DR
                                  Gov_score Sustain_Perf Sust_Commit
            Excluded instruments: Instrumental
            Partialled-out:       _cons
                                  nb: total SS, model F and R2s are after partialling-out;
                                      any small-sample adjustments include partialled-out
                                      variables in regressor count K
            ------------------------------------------------------------------------------
            
            Absorbed degrees of freedom:
            -----------------------------------------------------+
             Absorbed FE | Categories  - Redundant  = Num. Coefs |
            -------------+---------------------------------------|
                      id |       281           0         281     |
                    year |        19           1          18     |
            -----------------------------------------------------+

            Comment


            • #7
              Code:
               
               ivreghdfe EQUITY FSIZE OP_CF SD_OCF TAX  BM LEV MA DPP RPP PSIZE DR Gov_score Sustain_Perf Sust_Commit (CSO = Instrumental), first absorb(id year) cluster(id) resid endog(CSO)
              the resid option produces _reghdfe_resid. Look for missing values, which are the excluded observations.

              Comment


              • #8
                please Prof George

                i tried to run the code but unfortunately , it give me

                HTML Code:
                  ivreghdfe EQUITY FSIZE OP_CF SD_OCF TAX  BM LEV MA DPP RPP PSIZE DR Gov_score Sustain_Perf Sust_Commit (CSO = Instrumental), first absorb(id year) cluster(id) resid endog(CSO)
                option resid not allowed

                Comment


                • #9
                  hmm. no problems at my end with it.

                  try

                  ssc install reghdfe, replace

                  Comment


                  • #10
                    might try reghdfe, include CSO, and see if you get the same number of singularities.

                    Comment


                    • #11
                      Hussein: You haven't properly specified "resid." It's supposed to be something like resid(uhat).

                      Comment


                      • #12
                        with reghdfe or ivreghdfe, if you just put in resid alone, then it produces _reghdfe_resid as the resid. but you can name them, say uhat as Jeff suggests.

                        Comment


                        • #13
                          Please professor

                          when i try to see the the residual it work for ivreghdfe but when i try to do it for xtivreg2 it does not work , can you guide me how can i identify residual for xtivreg2

                          This is the code i used for ivreghdfe


                          qui: ivreghdfe EQUITY FSIZE OP_CF SD_OCF TAX BM LEV MA DPP RPP PSIZE DR Gov_score Sustain_Perf Sust_Commit (CSO = CSO_Percentage), first absorb(id year) endog(CSO) resid
                          predict resid1, residuals

                          This is the code i used for xtivreg2

                          xtset id year
                          ssc install xtivreg2, replace
                          tab year , generate(yr)

                          qui: xtivreg2 EQUITY FSIZE OP_CF SD_OCF TAX BM LEV MA DPP RPP PSIZE DR Gov_score Sustain_Perf Sust_Commit yr2-yr19 (CSO = Instrumental), fe first endog(CSO) resid
                          predict resid1, residuals

                          HTML Code:
                           . . qui: xtivreg2 EQUITY   FSIZE OP_CF SD_OCF TAX   BM LEV MA DPP RPP PSIZE   DR  Gov_score Sustain_Perf Sust_Commit   yr2-yr19 (CSO = Inst
                          > rumental),  fe first  endog(CSO) resid
                          option resid not allowed
                          r(198);
                          
                          end of do-file
                          
                          r(198);
                          Last edited by hussein bataineh; 10 Jun 2024, 14:51.

                          Comment


                          • #14
                            after xtivreg2, you should be able to

                            predict uhat, residuals

                            or, you could try

                            list id year if !e(sample)

                            Comment


                            • #15
                              Please professor do you have any note why it wok for ivreghdfe but not to xtivreg2

                              Comment

                              Working...
                              X